package com.eric.controller;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.annotation.SaMode;
import cn.dev33.satoken.util.SaResult;
import com.eric.domain.dto.EquipTransferDto;
import com.eric.service.IEquipTransferService;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.RequiredArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;

/**
 * <p>
 * 设备转移登记表 前端控制器
 * </p>
 *
 * @author 新哥
 * @since 2024-03-12
 */
@RestController
@RequestMapping("/equip-transfer")
@RequiredArgsConstructor
public class EquipTransferController {
    private final IEquipTransferService equipTransferService;

//    修改一条数据
    @PutMapping("/modifyOne")
    @SaCheckPermission("sys:modify")
    @SaCheckRole(value = {"sys:coder","sys:superAdmin","sys:admin","sys:manager"},mode = SaMode.OR)
    public SaResult modifyOne(EquipTransferDto equipTransferDto, MultipartFile[] photoFiles, HttpServletRequest request,String[] photoList){
       return equipTransferService.modifyOneService(equipTransferDto,photoFiles,request,photoList);
    }

//    根据id删除一条数据
    @DeleteMapping("/{id}")
    @SaCheckRole(value = {"sys:coder","sys:superAdmin","sys:admin","sys:manager"},mode = SaMode.OR)
    @SaCheckPermission("sys:delete")
    public SaResult deleteOneById(@PathVariable("id") Integer id ){
        return equipTransferService.deleteOneByIdService(id);
    }

//    这个接口是在已经存在设备的前提下发起出场单。全新购买的设备，应该使用另外在equipmentController接口中实现
    @PostMapping("/saveOneByEqId")
    public SaResult saveOneByEqId(Integer id,String receivingProject,String description,MultipartFile[]photoFiles,HttpServletRequest request){
        return equipTransferService.saveOneByEqId(id,receivingProject,description,photoFiles,request);
    }

//    分页获取全部数据
    @GetMapping("/getAllByPage")
    public SaResult getAllByPage(Integer current,Integer pageSize){
        return  equipTransferService.getAllByPage(current,pageSize);
    }

//    配合上面分页获取全部数据接口，获取全部数据行（不是分页搜索获取到的部分数据）
    @GetMapping("/getAllCounts")
    public SaResult getAllCounts(){
        return equipTransferService.getAllCountsService();
    }

//    多功能时间段查询数据接口
    @GetMapping("/getByBetweenTimes")
    public SaResult getByBetweenTimes(@DateTimeFormat(iso=DateTimeFormat.ISO.DATE)Date start,@DateTimeFormat(iso=DateTimeFormat.ISO.DATE)Date end,Integer current,Integer pageSize){
        return equipTransferService.getByBetweenTimesService(start,end,current,pageSize);
    }

//    配合多功能时间段获取数据接口，获取全部数据行条数（不是分页搜索获取到的部分数据）
    @GetMapping("/getByBetweenTimesCountS")
    public SaResult getByBetweenTimesCounts(@DateTimeFormat(iso=DateTimeFormat.ISO.DATE)Date start,@DateTimeFormat(iso=DateTimeFormat.ISO.DATE)Date end){
      return equipTransferService.getByBetweenTimesCountsService(start,end);
    }


    //    多功能查询接口，这里面的name包括设备名、创建人，最后修改人，项目名称
    @GetMapping("/getAllByAllTypeName")
    public SaResult getAllByAllTypeName(String name,Integer current,Integer pageSize){
        return   equipTransferService.getAllByAllTypeName(name,current,pageSize);
    }


//    配合多功能查询接口，获取全部数据行条数（不是分页搜索获取到的部分数据）

    @GetMapping("/getAllByTypeNameCounts")
    public SaResult getAllByTypeNameCounts(String name){
        return equipTransferService.getAllByAllTypeNameCounts(name);
    }


    //   文件下载接口
    @PostMapping("/downLoadFiles")
    public void downloadFiles(@RequestBody String[] files, HttpServletResponse response) throws IOException {
        equipTransferService.downloadFilesService(files,response);
    }

//    根据id获取一条信息
    @GetMapping("{id}")
    public SaResult getOneById(@PathVariable("id")Integer id){
            return equipTransferService.getOneByIdService(id);
    }



/*****************************这些接口暂时不用*****************************************
    //    这个接口暂时不用
    @GetMapping("/getByCreateTime")
    @JsonFormat
    public SaResult getByCreateTime(@DateTimeFormat(iso=DateTimeFormat.ISO.DATE) Date createTime, Integer current, Integer pageSize){
        return equipTransferService.getByCreateTimeService(createTime,current,pageSize);
    }

    //    这个接口暂时不用
    @GetMapping("/getByUpdateTime")
    public SaResult getByUpdateTime(@DateTimeFormat(iso=DateTimeFormat.ISO.DATE)Date updateTime,Integer current,Integer pageSize){
        return equipTransferService.getByUpdateTimeService(updateTime,current,pageSize);
    }

    //    这个接口暂时不用
    @GetMapping("/getByReceivingProject")
    public SaResult getByReceivingProject(String projectName, Integer current,Integer pageSize){
        return equipTransferService.getByReceivingProjectService(projectName,current,pageSize);
    }

    //    这个接口暂时不用
    @GetMapping("/getByEqName")
    public SaResult getByEqName(String equipName,Integer current,Integer pageSize){
        return equipTransferService.getByEqNameService(equipName,current,pageSize);
    }

    //    这个接口暂时不用
    @GetMapping("/getByLastUpdateBy")
    public SaResult getByLastUpdateBy(String lastByName,Integer current,Integer pageSize){
        return equipTransferService.getByLastUpdateByService(lastByName,current,pageSize);
    }

    //    这个接口暂时不用
    @GetMapping("/getByCreateBy")
    public SaResult getByCreateBy(String createByName,Integer current,Integer pageSize){
        return equipTransferService.getByCreateByService(createByName,current,pageSize);
    }


    //    这个接口暂时不用
    @GetMapping("/getAllByMoon")
    public SaResult getAllByMoon(@DateTimeFormat(iso=DateTimeFormat.ISO.DATE) Date moonDate, Integer current,Integer pageSize){
        return equipTransferService.getAllByMoon(moonDate,current,pageSize);
    }

    //    这个接口暂时不用
    @DeleteMapping("/deleteByIds")
    public SaResult deleteByIds(@RequestBody ArrayList<Integer>ids){
        return equipTransferService.deleteByIdsService(ids);
    }*/




    /*****************************这些接口暂时不用******************************************/

}
